package cn.bluethink.eguan.core.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Id;
import javax.persistence.Table;

import cn.bluethink.eguan.model.core.EgBts;
import cn.bluethink.eguan.model.core.EgOType;
import cn.bluethink.eguan.model.core.EgObject;

/**
 * 金币流通记录实体
 * 
 * @author 苏州中科蓝迪公司所有(c)2016-2021
 * @version 0.3.0
 * @brief 驿馆+产品
 * @note 修订历史： 1.wanglei于2018/12/06设计并构建初始版本v0.3.0
 */
@Table(name = "eg_bts")
public class EgBtsEntity implements Serializable {

    private static final long serialVersionUID = -4444137565433889975L;

    // 主键
    @Id
    private Long id;

    // 来源账户
    private Long oA;

    // 交易的对象类型唯一标识
    private Integer otype;

    // 交易的对象唯一标识
    private Long oid;

    // 交易的对象名称
    private String oname;

    // 交易价格
    private Integer price;

    // 交易数量
    private Integer number;

    // 目的账户
    private Long dA;

    // 交易创建时间
    private Date ctime;

    public EgBtsEntity() {

    }

    /**
     * 创建金币流通记录实体
     * 
     * @param oAcount
     * @param obj
     * @param price
     * @param number
     * @param dAcount
     */
    public EgBtsEntity(Long oAcount, EgObject obj, Integer price, Integer number, Long dAcount) {
        this.oA = oAcount;
        if (obj != null && obj.getType() != null) {
            this.otype = obj.getType().getOtid();
            this.oid = obj.getId();
            this.oname = obj.getName();
        } else {
            this.otype = null;
            this.oid = null;
            this.oname = "";
        }
        this.price = price == null ? null : price;
        this.number = number == null ? null : number;
        this.dA = dAcount;
        this.ctime = new Date();
    }

    /**
     * 转业务模型
     * 
     * @return
     */
    public EgBts creatEgBts() {
        EgBts bts = new EgBts();
        bts.setId(id);
        if (oid != null && otype != null) {
            bts.setObj(new EgObject(oid, oname, new EgOType(otype, null)));
        } else {
            bts.setObj(null);
        }
        // number为空，说明不是商品
        if (number == null) {
            bts.setTotalBts(price);
            bts.setNumber(null);
        } else {
            bts.setTotalBts(price * number);
            bts.setNumber(number);
        }
        bts.setCtime(ctime);
        return bts;

    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getoA() {
        return oA;
    }

    public void setoA(Long oA) {
        this.oA = oA;
    }

    public Integer getOtype() {
        return otype;
    }

    public void setOtype(Integer otype) {
        this.otype = otype;
    }

    public Long getOid() {
        return oid;
    }

    public void setOid(Long oid) {
        this.oid = oid;
    }

    public String getOname() {
        return oname;
    }

    public void setOname(String oname) {
        this.oname = oname;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }

    public Long getdA() {
        return dA;
    }

    public void setdA(Long dA) {
        this.dA = dA;
    }

    public Date getCtime() {
        return ctime;
    }

    public void setCtime(Date ctime) {
        this.ctime = ctime;
    }
}
